package com.lottery.common.service.Impl;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.ClientException;
import com.lottery.common.contants.Constants;
import com.lottery.common.contants.ReQueryResult;
import com.lottery.common.model.UcpaasSms;
import com.lottery.common.service.SmsMssageService;
import com.lottery.common.utils.ConnectionUrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@Service
public class SmsMssageServiceImpl implements SmsMssageService {
    @Autowired
    private UcpaasSms sms;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Value("${networking}")
    private String networking;

    @Override
    public ReQueryResult sendMsg(NutMap nutMap) throws ClientException {
        ReQueryResult result=new ReQueryResult();

        if (StringUtils.isEmpty(nutMap.getString("code"))){
            String code=RandomUtil.randomNumbers(6);
            nutMap.setv("code", code);
        }
        log.info("smsTypeStr is {}, phone is {}, code is {}",nutMap.getString("smsTypeStr"),nutMap.getString("phone"),nutMap.getString("code"));
        sms.setMobile(nutMap.getString("phone"));
        sms.setTemplateid(nutMap.getString("templateCode"));
        sms.setParam(nutMap.getString("code")+","+String.valueOf(60*5));
        log.info("sms is {}",JSON.toJSONString(sms));
        String s= ConnectionUrlUtil.sendPostByJson("https://open.ucpaas.com/ol/sms/sendsms",JSON.toJSONString(sms));
        System.out.println(s);
        return result;
    }



}
